package base.File路径;

import java.io.File;

public class 统计文件夹大小 {
    public static void main(String[] args) {
        File f = new File("C:\\Users\\TUO\\Desktop\\Java_Web");
        long size = statistics(f);
        System.out.println((size/1024/1024)+" Mb");
    }

    public static long statistics(File src){
        long size = 0L;
        File[] files = src.listFiles();
//        if (files == null){
//            System.err.println("疑是含有系统文件，谨慎操作！");
//            throw new RuntimeException();
//        }
        if (files != null){
            for (File file : files) {
                if (file.isFile()){
                    size += file.length();
                }else {
                    size += statistics(file);
                }
            }
        }
        return size;
    }
}
